home *** CD-ROM | disk | FTP | other *** search
/ Workbench Add-On / Workbench Add-On - Volume 1.iso / BBS-Archive / Comm / AmiTCP30b2.lha / src / rpclib / pmap_clnt.c < prev    next >
C/C++ Source or Header  |  1994-03-09  |  4KB  |  132 lines

  1. /*
  2.  * $Id: pmap_clnt.c,v 1.2 1993/11/10 02:09:14 jraja Exp $
  3.  *
  4.  * $Log: pmap_clnt.c,v $
  5.  * Revision 1.2  1993/11/10  02:09:14  jraja
  6.  * Fixed includes.
  7.  * Changed close() on sockets to CloseSocket() for AMITCP.
  8.  *
  9.  */
  10. /* @(#)pmap_clnt.c    2.2 88/08/01 4.0 RPCSRC */
  11. /*
  12.  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
  13.  * unrestricted use provided that this legend is included on all tape
  14.  * media and as a part of the software program in whole or part.  Users
  15.  * may copy or modify Sun RPC without charge, but are not authorized
  16.  * to license or distribute it to anyone else except as part of a product or
  17.  * program developed by the user.
  18.  * 
  19.  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
  20.  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
  21.  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
  22.  * 
  23.  * Sun RPC is provided with no support and without any obligation on the
  24.  * part of Sun Microsystems, Inc. to assist in its use, correction,
  25.  * modification or enhancement.
  26.  * 
  27.  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
  28.  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
  29.  * OR ANY PART THEREOF.
  30.  * 
  31.  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
  32.  * or profits or other special, indirect and consequential damages, even if
  33.  * Sun has been advised of the possibility of such damages.
  34.  * 
  35.  * Sun Microsystems, Inc.
  36.  * 2550 Garcia Avenue
  37.  * Mountain View, California  94043
  38.  */
  39. #if !defined(lint) && defined(SCCSIDS)
  40. static char sccsid[] = "@(#)pmap_clnt.c 1.37 87/08/11 Copyr 1984 Sun Micro";
  41. #endif
  42.  
  43. /*
  44.  * pmap_clnt.c
  45.  * Client interface to pmap rpc service.
  46.  *
  47.  * Copyright (C) 1984, Sun Microsystems, Inc.
  48.  */
  49.  
  50. #include <sys/param.h>
  51. #include <rpc/rpc.h>
  52. #include <rpc/pmap_prot.h>
  53. #include <rpc/pmap_clnt.h>
  54. #include <sys/socket.h>
  55.  
  56. static struct timeval timeout = { 5, 0 };
  57. static struct timeval tottimeout = { 60, 0 };
  58.  
  59. /*
  60.  * Set a mapping between program,version and port.
  61.  * Calls the pmap service remotely to do the mapping.
  62.  */
  63. bool_t
  64. pmap_set(program, version, protocol, port)
  65.     u_long program;
  66.     u_long version;
  67.     int protocol;
  68.     u_short port;
  69. {
  70.     struct sockaddr_in myaddress;
  71.     int socket = -1;
  72.     register CLIENT *client;
  73.     struct pmap parms;
  74.     bool_t rslt;
  75.  
  76.     get_myaddress(&myaddress);
  77.     client = clntudp_bufcreate(&myaddress, PMAPPROG, PMAPVERS,
  78.         timeout, &socket, RPCSMALLMSGSIZE, RPCSMALLMSGSIZE);
  79.     if (client == (CLIENT *)NULL)
  80.         return (FALSE);
  81.     parms.pm_prog = program;
  82.     parms.pm_vers = version;
  83.     parms.pm_prot = protocol;
  84.     parms.pm_port = port;
  85.     if (CLNT_CALL(client, PMAPPROC_SET, xdr_pmap, &parms, xdr_bool, &rslt,
  86.         tottimeout) != RPC_SUCCESS) {
  87.         clnt_perror(client, "Cannot register service");
  88.         return (FALSE);
  89.     }
  90.     CLNT_DESTROY(client);
  91. #ifdef AMITCP
  92.     (void)CloseSocket(socket);
  93. #else
  94.     (void)close(socket);
  95. #endif
  96.     return (rslt);
  97. }
  98.  
  99. /*
  100.  * Remove the mapping between program,version and port.
  101.  * Calls the pmap service remotely to do the un-mapping.
  102.  */
  103. bool_t
  104. pmap_unset(program, version)
  105.     u_long program;
  106.     u_long version;
  107. {
  108.     struct sockaddr_in myaddress;
  109.     int socket = -1;
  110.     register CLIENT *client;
  111.     struct pmap parms;
  112.     bool_t rslt;
  113.  
  114.     get_myaddress(&myaddress);
  115.     client = clntudp_bufcreate(&myaddress, PMAPPROG, PMAPVERS,
  116.         timeout, &socket, RPCSMALLMSGSIZE, RPCSMALLMSGSIZE);
  117.     if (client == (CLIENT *)NULL)
  118.         return (FALSE);
  119.     parms.pm_prog = program;
  120.     parms.pm_vers = version;
  121.     parms.pm_port = parms.pm_prot = 0;
  122.     CLNT_CALL(client, PMAPPROC_UNSET, xdr_pmap, &parms, xdr_bool, &rslt,
  123.         tottimeout);
  124.     CLNT_DESTROY(client);
  125. #ifdef AMITCP
  126.     (void)CloseSocket(socket);
  127. #else
  128.     (void)close(socket);
  129. #endif
  130.     return (rslt);
  131. }
  132.